package View.MaintainPage.gShow;


import View.MaintainPage.gMain.Mainweihu;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
import sx.dao.GoodsDao;
import sx.entity.Goods;

import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.ResourceBundle;

public class Mainshow extends Application implements Initializable {
    @FXML
    private TableColumn<String, String> goodsprice;

    @FXML
    private TableColumn<String, Integer> goodsid;

    @FXML
    private Button show;

    @FXML
    private Button endButton;

    @FXML
    private TableColumn<String,String> goodsname;
    @FXML
    private TableView<Goods> tableV;
    @FXML
    private TableColumn<String, Integer> goodsnum;
    @FXML
    void act1(ActionEvent event) {
//    	initialize(null, null);
    }

  @FXML  //������ת
    void Rback(ActionEvent event) {
    	try {
			 new Mainweihu().start(new Stage());//��ѯ��Ʒ����
			 
		} catch (Exception e) {
			// TODO: handle exception
		}
    	exitButtonOnMouseClicked(endButton);
    }


    
	@Override
	public void start(Stage primaryStage) {

		try {
			Class clazz = getClass();
			Parent root = FXMLLoader.load(clazz.getResource("Mainshow.fxml"));
			Scene scene = new Scene(root, 600, 600);
			scene.getStylesheets().add(getClass().getResource("/sources/Css/application1.css").toExternalForm());
			primaryStage.setScene(scene);
			primaryStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

    public void exitButtonOnMouseClicked(Button exitButton) {
        Stage stage = (Stage)exitButton.getScene().getWindow();
        stage.close();
    }

	public static void main(String[] args) {
		launch(args);
	}
	public void showList(){
		ObservableList<Goods> list = FXCollections.observableArrayList();
		ArrayList<Goods> goodsshow = new GoodsDao().displayGoods();
		goodsid.setCellValueFactory(new PropertyValueFactory<>("gid"));
		goodsname.setCellValueFactory(new PropertyValueFactory<>("gname"));
		goodsprice.setCellValueFactory(new PropertyValueFactory<>("gprice"));
		goodsnum.setCellValueFactory(new PropertyValueFactory<>("gnum"));
		Iterator<Goods> iterator=goodsshow.iterator();
		while(iterator.hasNext()){	
			Goods goods=iterator.next();
			list.add(goods);
			}
		System.out.println(list);
		tableV.setItems(list);
		
	}

	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {
		showList();// TODO Auto-generated method stub
		
	}
	}


